package hn.sigit.model.hnd.administrative;

import hn.sigit.model.commons.ISpatialZone;
import hn.sigit.model.hnd.cadastre.HND_SpatialZone;
import hn.sigit.model.ladm.administrative.LA_AdministrativeSource;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@org.hibernate.annotations.Proxy(lazy=false)
@Table(name="HND_Transaction", schema="hnd_administrative")
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class HND_Transaction implements Serializable {
	private static final long serialVersionUID = 1L;
	
	private Long id;
	private Date startDate;
	private Date completionDate;
	private String description;
	private String editorUserName;
	private String editorFullName;

	private Set<LA_AdministrativeSource> sources = new HashSet<LA_AdministrativeSource>();
	private Set<HND_SpatialZone> originatedSpatialZones = new HashSet<HND_SpatialZone>();
	
	
	@Id
	@Column(name="ID", nullable=false)
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="hnd_transaction_id_gen")
	@SequenceGenerator(name="hnd_transaction_id_gen", sequenceName="hnd_transaction_id_seq", allocationSize=1)
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	@Transient
	public Long getORMID() {
		return getId();
	}
	

	@Column(name="StartDate", nullable=false)
	public Date getStartDate() {
		return startDate;
	}
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}
	
	
	
	@Column(name="Description", nullable=true, length=255)
	public String getDescription() {
		return description;
	}
	public void setDescription(String value) {
		this.description = value;
	}
	
	
	@Column(name="CompletionDate", nullable=true)
	public Date getCompletionDate() {
		return completionDate;
	}
	public void setCompletionDate(Date completionDate) {
		this.completionDate = completionDate;
	}

	
	
	@Column(name="EditorUserName", nullable=true, length=255)
	public String getEditorUserName() {
		return editorUserName;
	}
	public void setEditorUserName(String editorUserName) {
		this.editorUserName = editorUserName;
	}
	
	@Column(name="EditorFullName", nullable=true, length=255)
	public String getEditorFullName() {
		return editorFullName;
	}
	public void setEditorFullName(String editorFullName) {
		this.editorFullName = editorFullName;
	}
	
	@OneToMany(targetEntity=LA_AdministrativeSource.class, fetch=FetchType.LAZY)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN})	
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.TRUE)
	public Set<LA_AdministrativeSource> getSources() {
		return sources;
	}
	public void setSources(java.util.Set<LA_AdministrativeSource> sources) {
		this.sources = sources;
	}
	
	@OneToMany(mappedBy="originatingTransaction", targetEntity=HND_SpatialZone.class)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.TRUE)
	public Set<HND_SpatialZone> getOriginatedSpatialZones() {
		return originatedSpatialZones;
	}
	@SuppressWarnings("unchecked")
	public void setOriginatedSpatialZones(Set<? extends ISpatialZone> originatedSpatialZones) {
		this.originatedSpatialZones = (Set<HND_SpatialZone>) originatedSpatialZones;
	}

	@Transient
	public abstract Long getPresentationId();
	protected abstract void setPresentationId(Long value);

	public String toString() {
		return String.valueOf(getId());
	}
}
